class PulvesController < ApplicationController
  # GET /pulves
  # GET /pulves.xml
  def index
    @pulves = Pulve.find(:all)
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @pulves }
    end
  end
  #test modif mlv!
  # GET /pulves/1
  # GET /pulves/1.xml
  def show
    @pulve = Pulve.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @pulve }
    end
  end

  # GET /pulves/new
  # GET /pulves/new.xml
  def new
    @pulve = Pulve.new
    @pulve.putoparcelles.build     
    @pulve.putofactures.build     

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @pulve }
    end
  end

  # GET /pulves/1/edit
  def edit
    @pulve = Pulve.find(params[:id])
  end

  # POST /pulves
  # POST /pulves.xml
  def create
    @pulve = Pulve.new(params[:pulve])
    respond_to do |format|
      #remplacer pulve.save par update_attr... comme dans la fonction d'update!
      if @pulve.save
        flash[:notice] = 'Pulve was successfully created.'
        format.html { redirect_to(@pulve) }
        format.xml  { render :xml => @pulve, :status => :created, :location => @pulve }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @pulve.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /pulves/1
  # PUT /pulves/1.xml
  def update
    params[:pulve][:existing_putoparcelle_attributes] ||= {}
    params[:pulve][:existing_putofacture_attributes] ||= {}
    @pulve = Pulve.find(params[:id])

    # We need to have this here so it can call the attributes
    # Otherwise the model would have no idea that we want
    # to delete all of the existing subforms
#    params[:pulve][:existing_task_attributes] ||= {} 

    respond_to do |format|
      if @pulve.update_attributes params[:pulve]
        flash[:notice] = 'Pulve was successfully updated.'
        format.html { redirect_to(@pulve) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @pulve.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /pulves/1
  # DELETE /pulves/1.xml
  def destroy
    @pulve = Pulve.find(params[:id])
    @pulve.destroy

    respond_to do |format|
      format.html { redirect_to(pulves_url) }
      format.xml  { head :ok }
    end
  end
  
  private
  
  def save_in_transaction
    
  end
end
